﻿using AMC.SubstitutionCache.Services;
using Orchard.DisplayManagement.Implementation;

namespace AMC.SubstitutionCache.Handlers
{
    /// <summary>
    /// Responsible for listening to the shape displaying event and calling the ISubstitutionService.TryAddToken method
    /// </summary>
    public class SubstitutionShapeListener : ShapeDisplayEvents
    {
        private readonly ISubstitutionService _cacheService;

        public SubstitutionShapeListener(ISubstitutionService cacheService)
        {
            _cacheService = cacheService;
        }

        public override void Displaying(ShapeDisplayingContext context)
        {
            _cacheService.TryAddToken(context.Shape);
        }
    }
}